/*
 * Copyright(c) 2018-? the original author[Wien(luweien@aliyun.com)] or authors.
 *
 */
package org.doll.it.base.vo;

import java.util.List;

import org.springframework.data.domain.Page;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 分页VO
 * 
 * @author Wien(luweien@aliyun.com)
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class PageVO<T> extends RootVO {

	/**
	 * 当前页
	 */
	private Integer currPage;

	/**
	 * 每页大小
	 */
	private Integer pageSize;

	/**
	 * 是否最后一页
	 */
	private Boolean last;

	/**
	 * 是否第一页
	 */
	private Boolean first;

	/**
	 * 本页条数
	 */
	private Integer numberOfElements;

	/**
	 * 总条数
	 */
	private Long totalElements;

	/**
	 * 总页数
	 */
	private Integer totalPages;

	/**
	 * 内容
	 */
	private List<T> content;

	public PageVO() {
	}

	public PageVO(@SuppressWarnings("rawtypes") Page t) {
		this(t, null);
	}

	public PageVO(@SuppressWarnings("rawtypes") Page t, List<T> content) {
		if (t != null) {
			this.currPage = t.getNumber();
			this.first = t.isFirst();
			this.last = t.isLast();
			this.numberOfElements = t.getNumberOfElements();
			this.pageSize = t.getSize();
			this.totalElements = t.getTotalElements();
			this.totalPages = t.getTotalPages();
		}
		if (content != null) {
			this.content = content;
		}
	}
}
